<template>
	<view @click="show = true" class="view">
		<text class="title">{{date}}</text>
		<u-icon name="arrow-down-fill" size="16"></u-icon>
		
		<u-picker mode="time" v-model="show" :params="params" @confirm="confirm"
			:defaultTime="defaultTime"></u-picker>
	</view>
</template>

<script>
	import { formatDateByTimestamp } from '@/utils/utils.js'
	export default {
		name:"DateSelectView",
		props: {
			defaultTime: {
				type: String,
				default () {
					return '';
				}
			}
		},
		data() {
			return {
				date: null,
				show: false,
				params: {
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false,
					timestamp: true,
				},
			};
		},
		created() {
			let date = Date.parse(this.$props.defaultTime);
			this.date = formatDateByTimestamp(date, 'yyyy年mm月dd日');
		},
		methods: {
			confirm(res) {
				console.log(res);
				this.date = formatDateByTimestamp(res.timestamp, 'yyyy年mm月dd日');
				this.$emit('change', res);
			},
		}
	}
</script>

<style lang="scss">
	
	.view{
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.title{
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #333333;
		line-height: 65rpx;
		
		margin-right: 10rpx;
	}
</style>
